import ControllerManager from "./mvc/ControllerManager"
import DebugUtils from "./utils/DebugUtils"
import MathUtils from "./utils/MathUtils"
import DateUtils from "./utils/DateUtils"
import Log from "./utils/Log"
import StateMachine from "./fsm/StateMachine"
import StageUtils from "./utils/StageUtils"
import ViewManager from "./mvc/ViewManager"
import SceneManager from "./scene/manager/SceneManager"
import BuildInfo from "./consts/BuildInfo"
import GlobalInfo from "./consts/GlobalInfo"
import MessageCenter from "./utils/MessageCenter"
import HttpAPI from "./net/http/HttpAPI"
import ArrayUtils from "./utils/ArrayUtils"
import DeviceUtils from "./utils/DeviceUtils"
import NetManager from "./net/NetManager"
import LocalStorageUtils from "./utils/LocalStorageUtils"
import ResourceManager from "./resource/ResourceManager"
import SDKManager from "./sdk/SDKManager"
import PathUtils from "./utils/PathUtils"
import SoundManager from "./sound/SoundManager"
import TimerManager from "./utils/TimerManager"
import StringUtils from "./utils/StringUtils"
import HotUpdateManager from "./hot_update/HotUpdateManager"
import LayerManager from "./layer/LayerManager"
import FairyGUIUtil from "../game_main/misc/FairyGUIUtil"
/**
 * 游戏框架导出入口
 */
export default class App {

    /**
     * 游戏框架名称
     */
    public static GFKName: string = "CCGameFramework";

    /**
     * 游戏框架版本
     */
    public static GFKVersion: string = "1.0";

    /**
     *   访问参数
     */
    public static UrlParameters: Object = null;

    /**
     * 打包配置数据
     * @type {null}
     */
    public static BuildInfo: BuildInfo = null;

    /**
     * 全局配置数据
     * @type {null}
     */
    public static GlobalInfo: GlobalInfo = null;

    /**
     * 流程管理器
     * @type {null}
     */
    public static get Procedure(): StateMachine {
        return StateMachine.instance()
    }

    /**
     * 资源管理器
     * @type {ResourceManager}
     */
    public static get ResMgr(): ResourceManager {
        return ResourceManager.instance()
    }

    /**
     * 简单Http请求
     * @type {HttpAPI}
     */
    public static get Http(): HttpAPI {
        return HttpAPI.instance()
    }

    /**
     * 网络管理类
     * @type {NetManager}
     */
    public static get Net(): NetManager {
        return NetManager.instance()
    }

    /**
     * 消息调度中心
     * @type {MessageCenter}
     */
    public static get MessageCenter(): MessageCenter {
        return MessageCenter.instance(1)
    }

    /**
     * Stage操作相关工具类
     */
    public static get StageUtils(): StageUtils {
        return StageUtils.instance()
    }

    /**
     * 音乐管理类
     */
    public static get SoundMgr(): SoundManager {
        return SoundManager.instance()
    }


    /**
     * 模块管理类
     * @type {ControllerManager}
     */
    public static get ControllerMgr(): ControllerManager {
        return ControllerManager.instance()
    }

    /**
     * View管理类
     * @type {ViewManager}
     */
    public static get ViewMgr(): ViewManager {
        return ViewManager.instance()
    }

    /**
     * 场景管理类
     * @type {SceneManager}
     */
    public static get SceneMgr(): SceneManager {
        return SceneManager.instance()
    }

    /**
     * 日期工具类
     * @type {DateUtils}
     */
    public static get DateUtils(): DateUtils {
        return DateUtils.instance()
    }

    /**
     * 数学计算工具类
     * @type {MathUtils}
     */
    public static get MathUtils(): MathUtils {
        return MathUtils.instance()
    }

    /**
     * 调试工具
     * @type {DebugUtils}
     */
    public static get DebugUtils(): DebugUtils {
        return DebugUtils.instance()
    }

    /**
     * 数组工具类
     * @returns {any}
     * @constructor
     */
    public static get ArrayUtils(): ArrayUtils {
        return ArrayUtils.instance()
    }

    /**
     * 设备工具类
     */
    public static get DeviceUtils(): DeviceUtils {
        return DeviceUtils.instance()
    }

    /**
     * 渠道SDK管理器
     */
    public static get SDK(): SDKManager {
        return SDKManager.instance()
    }

    /**
     * 路径实用类
     * @returns {PathUtil}
     * @constructor
     */
    public static get PathUtil(): PathUtils {
        return PathUtils.instance()
    }

    /**
     * 计时器
     * @returns {TimerManager}
     * @constructor
     */
    public static get TimerMgr(): TimerManager {
        return TimerManager.instance()
    }

    /**
     * 字符串工具类
     */
    public static get StrUtil(): StringUtils {
        return StringUtils.instance()
    }
    /**
     * 资源热更模块
     */
    public static get HotUpdateMgr(): HotUpdateManager {
        return HotUpdateManager.instance()
    }


    /**
     * 初始化函数
     * @constructor
     */
    public static init(): void {
        App.DebugUtils.isOpen(App.BuildInfo.IsDebug || App.UrlParameters["isDebug"])
        Log.info("游戏名称: ", App.GFKName)
        Log.info("游戏版本: ", App.GFKVersion)
        Log.info("引擎版本: ", cc.ENGINE_VERSION)
        App.DebugUtils.setThreshold(5)
        // 设置本游戏本地持久化的 key 前缀
        LocalStorageUtils.setHashID(App.BuildInfo.PackageName)
    }

    public static deinit(): void {
        StateMachine.destroy()
        SceneManager.destroy()
        LayerManager.deinit()
        ControllerManager.destroy()
        ViewManager.destroy()
        FairyGUIUtil.removeAllPackages()
        App.ResMgr.release()
        ResourceManager.destroy()
        App.StageUtils.clear()
        StageUtils.destroy()
    }
}
